﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace DAL
{
    using DAL.Entities;

    public class Dongiadichvu_clsDAL : BaseDAL, UTL.IBaseDAL 
    {
        public int Count()
        {
            throw new NotImplementedException();
        }

        public DataTable Select()
        {
            string sql = @" SELECT *,b.tendichvu FROM dongiadichvu_cls a join dichvu_cls b on a.madichvu=b.madichvu";
            return ExecuteQuery(sql);
        }

        public DataTable Select(object obj)
        {
            throw new NotImplementedException();
        }

        public object GetByKey(object key)
        {
            throw new NotImplementedException();
        }

        public bool Delete(string id)
        {
            string sql = @"DELETE FROM dongiadichvu_cls WHERE madichvu = '{0}'";
            sql = string.Format(sql,id);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Insert(object obj)
        {
            var o = (dongiadichvu_cls)obj;
            string sql = @"set dateformat mdy;INSERT INTO dongiadichvu_cls(madichvu,ngay,dongia) VALUES('{0}','{1}',{2})";
            sql = string.Format(sql,o.madicvu,o.ngay,o.dongia);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Update(object obj)
        {
            var o = (dongiadichvu_cls)obj;
            string sql = @"set dateformat mdy;UPDATE dongiadichvu_cls SET ,dongia={1} where ngay='{0}' and madichvu='{2}'";
            sql = string.Format(sql,o.ngay,o.dongia,o.madicvu);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public DataTable Search(string name)
        {
            throw new NotImplementedException();
        }

        public DataTable Select_dichvu_cls()
        {
            string sql = @" SELECT madichvu as id, tendichvu as ten FROM dichvu_cls";
            return ExecuteQuery(sql);
        }
        public DataTable Select_max()
        {
            string sql = @"SELECT max(madichvu) as id FROM dongiadichvu_cls";
            return ExecuteQuery(sql);
        }



        public bool deleteobj(object obj)
        {
            throw new NotImplementedException();
        }
    }
}
